home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / source / texture / texmap.asm < prev    next >
Encoding:
Assembly Source File  |  1993-10-04  |  22.2 KB  |  972 lines

  1. ;╔═══════════════════════════════════════════════════════════════════════════╗
  2. ;║                                                                           ║
  3. ;║                Polygonfiller for Texturemapped polygons                   ║
  4. ;║                                                                           ║
  5. ;║          Draws a Texture-mapped polygon in Tweakedmode (320x200)          ║
  6. ;║                                                                           ║
  7. ;║                          Programmed by Fantom                             ║
  8. ;║                                                                           ║
  9. ;║                 (c) An Ultimate Brains Production (c)                     ║
  10. ;║                                                                           ║
  11. ;║                     Version 2.4 / 17.8.93 / 12.19                         ║
  12. ;║                                                                           ║
  13. ;╚═══════════════════════════════════════════════════════════════════════════╝
  14.  
  15. ;                       Texture Mapping
  16. ;                       ---------------
  17.  
  18. ;        ╔═════════════╦═══════════════════════════╗
  19. ;        ║ UPPER 16BIT ║        LOWER 16BIT        ║
  20. ;╔═══════╬═════════════╬═════════════╦═════════════╣  Inner: add ecx,eax
  21. ;║  REG  ║   HI WORD   ║   HI BYTE   ║   LO BYTE   ║         adc ebx,ebp
  22. ;╠═══════╬═════════════╬═════════════╬═════════════╣         adc bh,dl
  23. ;║  EAX  ║  X-INC LSW  ║     ---     ║     ---     ║         mov dh,[ds:bx]
  24. ;╠═══════╬═════════════╬═════════════╬═════════════╣         mov [es:di],dh
  25. ;║  ECX  ║  TXT-X LSW  ║     ---     ║  LOOPCOUNT  ║         add di,80
  26. ;╠═══════╬═════════════╬═════════════╬═════════════╣         loop Inner
  27. ;║  EDX  ║     ---     ║ TEXTUREDATA ║    Y-INC    ║
  28. ;╠═══════╬═════════════╬═════════════╬═════════════╣
  29. ;║  EBP  ║  Y-INC LSW  ║ X-INC  SIGN ║    X-INC    ║
  30. ;╠═══════╬═════════════╬═════════════╬═════════════╣
  31. ;║  EBX  ║  TXT-Y LSW  ║  TEXTURE Y  ║  TEXTURE X  ║
  32. ;╚═══════╩═════════════╩═════════════╩═════════════╝
  33.  
  34.     Ideal
  35.     model small
  36.     P386
  37.  
  38. SC_INDEX                equ     03c4h   ;Sequence Controller Index
  39. CRTC_INDEX              equ     03d4h   ;CRT Controller Index
  40. MISC_OUTPUT             equ     03c2h   ;Miscellaneous Output register
  41. SCREEN_SEG              equ     0a000h  ;segment of display memory in TweakM
  42. SCREEN_WIDTH            equ     320
  43. MAP_MASK                equ     2       ;Map Mask register index in SC
  44. INPUT_STATUS_1          equ     03dah   ;Input Status 1 register
  45. START_ADDRESS_HIGH      equ     0ch     ;bitmap start address high db
  46. START_ADDRESS_LOW       equ     0dh     ;bitmap start address low db
  47. Row                     =       0
  48.  
  49. ;════════════════════════
  50.     MACRO sini                              ;;eax=sin(ax)*32768
  51. ;════════════════════════
  52.  
  53.     and ax,255
  54.     shl ax,1
  55.     push bx
  56.     mov bx,ax
  57.     xor eax,eax
  58.     mov ax,[sintable+bx]
  59.     pop bx
  60.  
  61.     ENDM
  62.  
  63. ;════════════════════════
  64.     MACRO kosini                            ;;eax=cos(ax)*32768
  65. ;════════════════════════
  66.  
  67.     add ax,64
  68.     and ax,255
  69.     shl ax,1
  70.     push bx
  71.     mov bx,ax
  72.     xor eax,eax
  73.     mov ax,[sintable+bx]
  74.     pop bx
  75.  
  76.     ENDM
  77.  
  78. ;════════════════════════════════════════════════════════════════════════════
  79.     Segment Code 'Code'                 ;Ok... Let's code it!
  80. ;════════════════════════════════════════════════════════════════════════════
  81.  
  82.     Assume cs:Code,ds:Data
  83.  
  84. Start:  call InitD                      ;Let's Init this crap!
  85.     call Tweakon                    ;Tweaked mode ON
  86.     call SetPalette                 ;Let's set the palette
  87.  
  88. Again:  call waitborder                 ;Here we just do a stupid
  89.     call Rotate                     ;Loop.. Rotations, projections
  90.     call Proj                       ;And stuff like that...
  91.     call clean
  92.     call Texture                    ;Let's Draw IT!
  93.     call showp                      ;Change active window
  94.     add [XRot+4],1                  ;Rotation of the next frame
  95.     mov ah,0bh                      ;Do you wanna quit?
  96.     int 21h
  97.     cmp al,0ffh
  98.     jne Again
  99.     mov ah,7
  100.     int 21h
  101.     cmp al,1bh                      ;Yes you will! -> Stop
  102.     je Stop
  103.     jmp Again                       ;Until then ---> LOOOOOPPP
  104. Stop:   mov ax,3                        ;Let's get the hell out of here
  105.     int 10h
  106.     mov ax,4c00h
  107.     int 21h
  108.  
  109. ;════════════════════════
  110.     Proc Texture
  111. ;════════════════════════
  112.  
  113.  
  114.     xor bx,bx                       ;Actually BX = PolNumber to be drawn!
  115.     call TopLeft                    ;Find the upperleft corner
  116.     call InitTex                    ;Init texture
  117.  
  118. FillL:  call FillIt                     ;Fill-loop... Fill the first V-line
  119.     dec [Top]                       ;First Line done. Next TopEdge?
  120.     jge NoSrcT                      ;If not -> NoSrcT
  121.     call NewSTop                    ;Else get new SourceTopLine
  122.     dec [Top]                       ;TopLineDX - 1
  123.     jmp SkipST                      ;No advance for the first point
  124. NoSrcT: mov eax,[SrcTXA]                ;Let's advance along the SrcTop
  125.     mov ebx,[SrcTYA]                ;.....
  126.     add [SrcTX],eax                 ;.....
  127.     add [SrcTY],ebx                 ;.....
  128. SkipST: dec [Bot]                       ;And let's do it on Bottom line too!
  129.     jge NoSrcB                      ;This is the same thing as above..
  130.     call NewSBot                    
  131.     dec [Bot]
  132.     jmp SkipSB
  133. NoSrcB: mov eax,[SrcBXA]                ;Advance...
  134.     mov ebx,[SrcBYA]
  135.     add [SrcBX],eax
  136.     add [SrcBY],ebx
  137.  
  138. SkipSB: inc [DestTX]                    ;Advance along DESTINATION..
  139.     dec [DTop]                      ;Next DestTopLine?
  140.     jge NoDTop                      ;If not -> NoDTop
  141.     call NewTop                     ;Else get new DestinationTopLine
  142.     jmp SkipDT                      ;No advance for the first point
  143. NoDTop: mov eax,[DestTYA]               ;Advance...
  144.     add [DestTY],eax
  145.  
  146. SkipDT: dec [DBot]                      ;Do the same thing as above...
  147.     jge NoDBot
  148.     call NewBot
  149.     jmp SkipDB
  150. NoDBot: mov eax,[DestBYA]
  151.     add [DestBY],eax
  152.  
  153. SkipDB: dec [PolWidht]                  ;Is there any V-lines to draw?
  154.     jge FillL                       ;If there is -> FillL
  155.     ret                             ;That's all!
  156.  
  157.     ENDP
  158.  
  159. ;════════════════════════
  160.     Proc FillIt
  161. ;════════════════════════
  162.  
  163.     mov dx,SC_INDEX                 ;Let's prepare SC_INDEX
  164.     mov al,MAP_MASK                 ;For the MAP_MASK
  165.     out dx,al                       ;.....
  166.     mov ax,[Word DestBY+2]          ;How many pixels to Draw?
  167.     sub ax,[Word DestTY+2]          ;.....
  168.     jl SkipIt                       ;If < 0 nothing to draw -> SkipIt
  169.     inc ax                          ;Plus one
  170.     mov [Dest],ax                   ;Dest = pixels to draw
  171.  
  172.     mov eax,[SrcTX]                 ;Initial start and end point
  173.     mov edx,[SrcTY]                 ;for source line
  174.     mov ebx,[SrcBX]
  175.     mov ecx,[SrcBY]
  176.  
  177.     sub ebx,eax                     ;Calculate DX and DY
  178.     sub ecx,edx
  179.     mov eax,ebx
  180.     mov bx,[Dest]                   ;Divide them by Dest
  181.     movsx ebx,bx
  182.     cdq
  183.     idiv ebx
  184.     mov [SXA],eax                   ;SourceX advance / dest. pixel
  185.     mov eax,ecx
  186.     cdq
  187.     idiv ebx
  188.     mov [SYA],eax                   ;SourceY advance / dest. pixel
  189.  
  190.     mov ax,SCREEN_SEG               ;Calculate Init Pixel on dest. 
  191.     add ax,[PageOffset]             ;V-line
  192.     mov es,ax                       ;.....
  193.     mov bx,[Word DestTY+2]
  194.     add bx,bx
  195.     mov di,[Rows+bx]
  196.     mov bx,[DestTX]
  197.     mov cx,bx
  198.     shr bx,2
  199.     add di,bx
  200.     and cx,3
  201.     mov al,1
  202.     shl al,cl
  203.     mov dx,SC_INDEX+1               ;Don't forget the mask!
  204.     out dx,al                       ;.....
  205.  
  206.     mov ebp,[SYA]                   ;Let's initialize registers
  207.     rol ebp,16                      ;for InnerLoop...
  208.     mov dx,bp                       ;BH = Src Y-coordinate
  209.     mov eax,[SXA]                   ;BL = Src X-coordinate
  210.     rol eax,16                      ;Notice!!:
  211.     mov bp,ax                       ;---------
  212.     xor ax,ax                       ;Source image is assumed to be
  213.     mov ecx,[SrcTX]                 ;256-pixels wide. Therefore 
  214.     rol ecx,16                      ;Indexing table with BX gives you
  215.     mov ebx,[SrcTY]                 ;directly source pixel (BH,BL)!
  216.     rol ebx,16                      ;.....
  217.     mov bh,bl
  218.     mov bl,cl
  219.  
  220.     mov cx,[Dest]                   ;Number of pixels to be drawn
  221.     dec cx                          ;.....
  222.     jz SkipIt                       ;.....
  223.  
  224. InnerL: add ecx,eax                     ;These are fixed-point calculations
  225.     adc ebx,ebp                     ;Try to figure it out by yourself
  226.     adc bh,dl                       ;There is a table in the beginning
  227.     mov dh,[Tex+bx]                 ;of this file to determine the usage
  228.     mov [es:di],dh                  ;of registers..
  229.     add di,80                       ;Next Row..
  230.     loop InnerL                     ;Continue until V-line is drawn
  231. SkipIt: ret
  232.  
  233.     ENDP
  234.  
  235. ;════════════════════════
  236.     Proc InitTex
  237. ;════════════════════════
  238.  
  239.     mov ax,[TopP]                   ;Initialize Source and destination
  240.     mov [CurTE],ax                  ;Lines
  241.     mov [CurBE],ax                  ;CurTE = Current Topline End
  242.     mov [CurSTE],ax                 ;CurSTE = Current Src Topline End
  243.     mov [CurSBE],ax                 ;.....
  244.  
  245.     call NewTop                     ;Init...
  246.     call NewBot
  247.     call NewSTop
  248.     call NewSBot
  249.     ret
  250.  
  251.     ENDP
  252.  
  253. ;════════════════════════
  254.     Proc NewSTop
  255. ;════════════════════════
  256.  
  257.     mov ax,[NTop]                   ;DX of the new Dest. Topline
  258.     mov [Top],ax                    ;Store it
  259.  
  260.     mov bx,[CurSTE]                 ;Current Src Top End
  261.  
  262.     add bx,bx                       ;BX = BX*2
  263.     mov bx,[TPol+bx]                ;Get number of that point
  264.     shl bx,2                        ;multiply by 4
  265.     mov ax,[TPisteet+bx]            ;X-coordinate (TPisteet=TexturePoints)
  266.     mov cx,[TPisteet+bx+2]          ;Y-coordinate
  267.  
  268.     mov bx,[CurSTS]                 ;Current Src Top Start
  269.     add bx,bx                       ;...
  270.     mov bx,[TPol+bx]
  271.     shl bx,2
  272.     sub ax,[TPisteet+bx]            ;Current Src Top DX
  273.     sub cx,[TPisteet+bx+2]          ;Current Src Top DY
  274.  
  275.     mov dx,[TPisteet+bx]            ;Init point for source line
  276.     mov bx,[TPisteet+bx+2]          ;.....
  277.     shl ebx,16                      ;Make it fixed-point
  278.     shl edx,16
  279.     mov [SrcTX],edx                 ;Store!
  280.     mov [SrcTY],ebx
  281.     mov si,[Top]                    ;Divide Src Top DX and DY
  282.     inc si                          ;by Destination line DX+1
  283.     movsx esi,si                    ;....
  284.     movsx eax,ax
  285.     shl eax,16
  286.     cdq
  287.     idiv esi
  288.     mov [SrcTXA],eax                ;SrcTopX Initpoint advance / V-line
  289.     add [SrcTX],eax                 ;Add it on InitPointX
  290.  
  291.     movsx eax,cx                    
  292.     shl eax,16
  293.     cdq
  294.     idiv esi
  295.     mov [SrcTYA],eax                ;SrcTopY Initpoint advance / V-line
  296.     add [SrcTY],eax                 ;Add it on InitpointY
  297.     ret
  298.  
  299.     ENDP
  300.  
  301. ;════════════════════════
  302.     Proc NewSBot
  303. ;════════════════════════
  304.  
  305.     mov ax,[NBot]                   ;Exactly the same thing as above
  306.     mov [Bot],ax                    ;But for Src Bottomline
  307.  
  308.     mov bx,[CurSBE]
  309.  
  310.     add bx,bx
  311.     mov bx,[TPol+bx]
  312.     shl bx,2
  313.     mov ax,[TPisteet+bx]
  314.     mov cx,[TPisteet+bx+2]
  315.  
  316.     mov bx,[CurSBS]
  317.     add bx,bx
  318.     mov bx,[TPol+bx]
  319.     shl bx,2
  320.     sub ax,[TPisteet+bx]
  321.     sub cx,[TPisteet+bx+2]
  322.  
  323.     mov dx,[TPisteet+bx]
  324.     mov bx,[TPisteet+bx+2]
  325.     shl ebx,16
  326.     shl edx,16
  327.     mov [SrcBX],edx
  328.     mov [SrcBY],ebx
  329.     mov si,[Bot]
  330.     inc si
  331.     movsx esi,si
  332.     movsx eax,ax
  333.     shl eax,16
  334.     cdq
  335.     idiv esi
  336.     mov [SrcBXA],eax
  337.     add [SrcBX],eax
  338.  
  339.     movsx eax,cx
  340.     shl eax,16
  341.     cdq
  342.     idiv esi
  343.     mov [SrcBYA],eax
  344.     add [SrcBY],eax
  345.     ret
  346.  
  347.     ENDP
  348.  
  349. ;════════════════════════
  350.     Proc NewTop
  351. ;════════════════════════
  352.  
  353. NewT:   mov ax,[CurTE]                  ;Current TopLine endpoint
  354.     mov [CurTS],ax                  ;Make it startpoint
  355.     mov [CurSTS],ax                 ;For Source too
  356.     mov bx,ax                       ;Let's take new endpoint
  357.     inc bx                          ;we are moving clockwise on
  358.     and bx,3                        ;polygons Vertexlist. There is
  359.     mov [CurTE],bx                  ;always 4 points in a list..
  360.     mov [CurSTE],bx                 ;(that should not be a constant..
  361.                     ;maybe in the next version...)
  362.     add bx,bx                       ;Init Dest Topline
  363.     mov bx,[Pol+bx]                 ;You have seen this part of code
  364.     shl bx,2                        ;Before...
  365.     mov ax,[Pisteet+bx]
  366.     mov cx,[Pisteet+bx+2]
  367.  
  368.     mov bx,[CurTS]
  369.     add bx,bx
  370.     mov bx,[Pol+bx]
  371.     shl bx,2
  372.     sub ax,[Pisteet+bx]             ;If DX = 0 let's have next Dest.
  373.     jz NewT                         ;edgeline (there is no reason to 
  374.     mov [DTop],ax                   ;scan vertical Edges) 
  375.     jge NoNeg                       ;Let's fix it by one...
  376.     sub ax,2                        ;i.e if DX < 0 -> minus 1
  377.     neg [DTop]                      ;    if DX > 0 -> plus 1
  378. NoNeg:  inc ax
  379.     sub cx,[Pisteet+bx+2]           ;Same thing on DY
  380.     jge NoNeg1
  381.     sub cx,2
  382. NoNeg1: inc cx
  383.  
  384.     mov bx,[Pisteet+bx+2]           ;New Destination Topline InitpointY
  385.     shl ebx,16                      ;Make it fixed point
  386.     mov [DestTY],ebx                ;Store
  387.  
  388.     mov si,[DTop]                   ;Let's calculate Dest Topline
  389.     mov [NTop],si                   ;Advances..
  390.     inc [NTop]
  391.  
  392.     movsx eax,cx
  393.     add si,2
  394.     movsx esi,si
  395.     shl eax,16
  396.     cdq
  397.     idiv esi
  398.     mov [DestTYA],eax               ;Here we have Dest Topline YAdvance
  399.     bt eax,31                       ;Let's do some fixing if necessary
  400.     jnc NoNeg2                      ;....
  401.     add [DestTY],eax
  402.     add [DestTY],10000h
  403. NoNeg2: ret
  404.  
  405.     ENDP
  406.  
  407. ;════════════════════════
  408.     Proc NewBot
  409. ;════════════════════════
  410.  
  411. NewB:   mov ax,[CurBE]                  ;Guess what.... it's all above....
  412.     mov [CurBS],ax
  413.     mov [CurSBS],ax
  414.     mov bx,ax
  415.     dec bx
  416.     and bx,3
  417.     mov [CurBE],bx
  418.     mov [CurSBE],bx
  419.  
  420.     add bx,bx
  421.     mov bx,[Pol+bx]
  422.     shl bx,2
  423.     mov ax,[Pisteet+bx]
  424.     mov cx,[Pisteet+bx+2]
  425.  
  426.     mov bx,[CurBS]
  427.     add bx,bx
  428.     mov bx,[Pol+bx]
  429.     shl bx,2
  430.     sub ax,[Pisteet+bx]
  431.     jz NewB
  432.     mov [DBot],ax
  433.     jge NoNeg3
  434.     sub ax,2
  435.     neg [DBot]
  436. NoNeg3: inc ax
  437.     sub cx,[Pisteet+bx+2]
  438.     jge NoNeg4
  439.     sub cx,2
  440. NoNeg4: inc cx
  441.  
  442.     mov bx,[Pisteet+bx+2]
  443.     shl ebx,16
  444.     mov [DestBY],ebx
  445.  
  446.     mov si,[DBot]
  447.     mov [NBot],si
  448.     inc [NBot]
  449.  
  450.     movsx eax,cx
  451.     add si,2
  452.     movsx esi,si
  453.     shl eax,16
  454.     cdq
  455.     idiv esi
  456.     mov [DestBYA],eax
  457.     bt eax,31
  458.     jnc NoNeg5
  459.     add [DestBY],10000h
  460.     ret
  461. NoNeg5: add [DestBY],eax
  462.     ret
  463.  
  464.     ENDP
  465.  
  466. ;════════════════════════
  467.     PROC TopLeft
  468. ;════════════════════════
  469.  
  470.     mov [Py],32767                  ;Here we just find out the
  471.     mov [Px],32767                  ;upperleft point of the polygon
  472.     mov [Sx],0                      ;SX = Biggest X
  473.  
  474.     mov ax,32767
  475.     xor bx,bx
  476.     xor si,si
  477.     xor ecx,ecx
  478.     mov di,[Poly+bx]
  479.     mov cx,4
  480.     mov [TopP],0
  481. Poll:   push ecx
  482.     mov cx,[ds:di]
  483.     mov bx,[Pisteet+ecx*4]          ;Pisteet = Points 
  484.     mov cx,[Pisteet+ecx*4+2]
  485.     cmp bx,ax
  486.     ja  Jatka2                      ;Jatka = Continue
  487.     mov ax,bx
  488.     mov [Px],bx
  489.     jl  ThisOne
  490.     cmp [Py],cx
  491.     jle Jatka2
  492. ThisOne:mov [Py],cx
  493.     mov [TopP],si
  494. Jatka2: cmp [Sx],bx
  495.     ja Menoks                       ;Menoks = GO!
  496.     mov [Sx],bx
  497. Menoks: inc si
  498.     add di,2
  499.     pop ecx
  500.     dec ecx
  501.     jnz poll
  502.     mov ax,[Sx]
  503.     sub ax,[Px]                     ;PX = Smallest X
  504.     inc ax
  505.     mov [PolWidht],ax               ;Polygon widht in pixels
  506.     mov ax,[Px]                     ;Let's start from the leftmost
  507.     mov [DestTX],ax                 ;Coordinate
  508.     ret
  509.  
  510.     ENDP
  511.  
  512. ;════════════════════════
  513.     PROC TweakOn
  514. ;════════════════════════
  515.  
  516.     mov     ax,13h                  ;Tweaked mode
  517.     int     10h                     ;Let the BIOS set up an
  518.     mov     dx,SC_INDEX             ;Ordinary 320x200 MCGA
  519.     mov     ax,0604h                ;....
  520.     out     dx,ax
  521.     mov     dx,SC_INDEX
  522.     mov     ax,0f02h
  523.     out     dx,ax
  524.     mov     ax,SCREEN_SEG
  525.     mov     es,ax
  526.     sub     di,di
  527.     sub     ax,ax
  528.     mov     cx,8000h
  529.     rep     stosw
  530.     mov     dx,CRTC_INDEX           ;Let's do some Tweaked things
  531.     mov     ax,14h
  532.     out     dx,ax
  533.     mov     ax,0e317h
  534.     out     dx,ax
  535.     ret
  536.  
  537.     ENDP
  538.  
  539. ;════════════════════════
  540.     PROC InitD
  541. ;════════════════════════
  542.  
  543.     cld                             ;Just initialize registers...
  544.     xor eax,eax
  545.     xor ebx,ebx
  546.     xor ecx,ecx
  547.     xor edx,edx
  548.     xor edi,edi
  549.     xor esi,esi
  550.     mov ax,Data
  551.     mov ds,ax
  552.     ret
  553.  
  554.     ENDP
  555.  
  556. ;════════════════════════
  557.     PROC SetPalette
  558. ;════════════════════════
  559.  
  560.     mov     si,Offset Pal           ;These palette routines
  561.     mov     al,0                    ;Are originally programmed
  562.     mov     dx,3c8h                 ;By Future Crew.. Thanx guys!
  563.     out     dx,al                   ;Them appear in their demo
  564.     mov     dx,3c9h                 ;Called Mental Surgery
  565.     mov     cx,768                  ;       ______________
  566. invid1: lodsb
  567.     out     dx,al
  568.     loop    invid1
  569.     ret
  570.  
  571.     ENDP
  572.  
  573. ;════════════════════════
  574.     PROC WaitBorder
  575. ;════════════════════════
  576.  
  577.     push    ax
  578.     push    dx
  579.     mov     dx,3dah
  580. wbr1:   in      al,dx
  581.     test    al,8
  582.     jnz     wbr1
  583. wbr2:   in      al,dx
  584.     test    al,8
  585.     jz      wbr2
  586.     pop     dx
  587.     pop     ax
  588.     ret
  589.  
  590.     ENDP
  591.  
  592. ;════════════════════════
  593.     PROC Rotate
  594. ;════════════════════════
  595.  
  596.     mov si,Offset Dpist             ;Let's rotate some coordinates 
  597.     mov di,Offset Rotated
  598.     mov cx,4                        ;Just four of them
  599.  
  600.     mov ax,[XRot]
  601.     sini
  602.     mov [KXSin],ax
  603.     mov ax,[XRot]
  604.     kosini
  605.     mov [KXCos],ax
  606.     mov ax,[XRot+2]
  607.     sini
  608.     mov [KYSin],ax
  609.     mov ax,[XRot+2]
  610.     kosini
  611.     mov [KYCos],ax
  612.     mov ax,[XRot+4]
  613.     sini
  614.     mov [KZSin],ax
  615.     mov ax,[XRot+4]
  616.     kosini
  617.     mov [KZCos],ax
  618.  
  619.     mov ax,[KZCos]                  ;Calculate Transformation
  620.     imul [KYCos]                    ;Matrix...
  621.     mov bx,dx                       ;(Long lives Selfmodification)
  622.     mov ax,[KZSin]
  623.     imul [KXSin]
  624.     shl dx,1
  625.     mov ax,[KYSin]
  626.     imul dx
  627.     add bx,dx
  628.     mov [Word @@A+1],bx
  629.  
  630.     mov ax,[KZSin]
  631.     neg ax
  632.     imul [KYCos]
  633.     mov bx,dx
  634.     mov ax,[KZCos]
  635.     imul [KXSin]
  636.     shl dx,1
  637.     mov ax,[KYSin]
  638.     imul dx
  639.     add bx,dx
  640.     mov [Word @@B+1],bx
  641.  
  642.     mov ax,[KXCos]
  643.     imul [KYSin]
  644.     mov [Word @@C+1],dx
  645.  
  646.     mov ax,[KZSin]
  647.     imul [KXCos]
  648.     mov [Word @@D+1],dx
  649.  
  650.     mov ax,[KZCos]
  651.     imul [KXCos]
  652.     mov [Word @@E+1],dx
  653.  
  654.     mov ax,[KXSin]
  655.     neg ax
  656.     sar ax,1
  657.     mov [Word @@F+1],ax
  658.  
  659.     mov ax,[KZCos]
  660.     neg ax
  661.     imul [KYSin]
  662.     mov bx,dx
  663.     mov ax,[KZSin]
  664.     imul [KXSin]
  665.     shl dx,1
  666.     mov ax,[KYCos]
  667.     imul dx
  668.     add bx,dx
  669.     mov [Word @@G+1],bx
  670.  
  671.     mov ax,[KZSin]
  672.     imul [KYSin]
  673.     mov bx,dx
  674.     mov ax,[KZCos]
  675.     imul [KXSin]
  676.     shl dx,1
  677.     mov ax,[KYCos]
  678.     imul dx
  679.     add bx,dx
  680.     mov [Word @@H+1],bx
  681.  
  682.     mov ax,[KXCos]
  683.     imul [KYCos]
  684.     mov [Word @@L+1],dx
  685.  
  686. RotL:
  687.  
  688. @@A:    mov ax,1234h
  689.     imul [Word si]
  690.     mov bx,dx
  691. @@B:    mov ax,1234h
  692.     imul [Word si+2]
  693.     add bx,dx
  694. @@C:    mov ax,1234h
  695.     imul [Word si+4]
  696.     add bx,dx
  697.     shl bx,2
  698.     mov [ds:di],bx
  699.  
  700. @@D:    mov ax,1234h
  701.     imul [Word si]
  702.     mov bx,dx
  703. @@E:    mov ax,1234h
  704.     imul [Word si+2]
  705.     add bx,dx
  706. @@F:    mov ax,1234h
  707.     imul [Word si+4]
  708.     add bx,dx
  709.     shl bx,2
  710.     mov [ds:di+2],bx
  711.  
  712. @@G:    mov ax,1234h
  713.     imul [Word si]
  714.     mov bx,dx
  715. @@H:    mov ax,1234h
  716.     imul [Word si+2]
  717.     add bx,dx
  718. @@L:    mov ax,1234h
  719.     imul [Word si+4]
  720.     add bx,dx
  721.     shl bx,2
  722.     mov [ds:di+4],bx
  723.  
  724.     add si,6
  725.     add di,8
  726.     dec cx
  727.     jnz RotL
  728.     ret
  729.  
  730. ENDP
  731.  
  732. ;════════════════════════
  733.     PROC Proj
  734. ;════════════════════════
  735.  
  736.     xor ecx,ecx                     ;And then...
  737.     xor edi,edi                     ;Let's project them...
  738.  
  739.     mov cx,1
  740. ML:     xor esi,esi
  741.     push cx
  742.     dec cx
  743.     mov si,[ObjDot+ecx*2]
  744.     mov cx,[si]
  745.     cmp cx,0
  746.     je  @@Next
  747.     add si,2
  748. ProL:   push cx
  749.     mov cx,[ecx*2+esi-2]
  750.     shl cx,2
  751.     mov bp,cx
  752.     add cx,cx
  753.     mov bx,[Rotated+ecx+4]
  754.     movsx ebx,bx
  755.     add ebx,[KZ]
  756.     add ebx,1024
  757.  
  758.     mov ax,[Rotated+ecx]
  759.     cwde
  760.     cdq
  761.     shl eax,8
  762.     idiv ebx
  763.     mov dx,ax
  764.     sar dx,2
  765.     add ax,dx
  766.     add ax,[XCenter]
  767.     mov [Pisteet+bp],ax
  768.  
  769.     mov ax,[Rotated+ecx+2]
  770.     cwde
  771.     neg eax
  772.     cdq
  773.     shl eax,8
  774.     idiv ebx
  775.     add ax,[YCenter]
  776.     mov [Pisteet+bp+2],ax
  777.  
  778.     pop cx
  779.     dec cx
  780.     jnz ProL
  781. @@Next: pop cx
  782.     dec cx
  783.     jnz ML
  784.     ret
  785.  
  786.     ENDP
  787.  
  788. ;════════════════════════
  789.     PROC Clean
  790. ;════════════════════════
  791.  
  792.     mov dx,SC_INDEX                 ;Vacuum suck!
  793.     mov ax,0f02h                    ;Clear the passive screen
  794.     out dx,ax
  795.     mov ax,SCREEN_SEG
  796.     add ax,[PageOffset]
  797.     mov es,ax
  798.     sub di,di
  799.     sub eax,eax
  800.     mov cx,4000
  801. lop:    rep stosd
  802.     ret
  803.  
  804.     ENDP
  805.  
  806. ;════════════════════════
  807.     PROC ShowP
  808. ;════════════════════════
  809.  
  810.     push    bx                      ;This is originally from
  811.     push    cx                      ;XSHARP!!
  812.     push    dx                      ;Little modifications done!
  813.     push    ax
  814.  
  815.     mov     bl,START_ADDRESS_LOW
  816.     mov     bh,[Byte ptr StartOffset]
  817.     mov     cl,START_ADDRESS_HIGH
  818.     mov     ch,[Byte ptr StartOffset+1]
  819.     mov     dx,CRTC_INDEX
  820.     mov     ax,bx
  821.     out     dx,ax
  822.     mov     ax,cx
  823.     out     dx,ax
  824.  
  825.     cmp     [PageOffset],0
  826.     jne     Page0
  827.     mov     [PageOffset],1024
  828.     mov     [StartOffset],16384
  829.     pop     ax
  830.     pop     dx
  831.     pop     cx
  832.     pop     bx
  833.     ret
  834.  
  835. Page0:  mov     [PageOffset],0
  836.     mov     [StartOffset],0
  837.     pop     ax
  838.     pop     dx
  839.     pop     cx
  840.     pop     bx
  841.     ret
  842.  
  843.     ENDP
  844.  
  845.     ENDS
  846.  
  847. ;════════════════════════════════════════════════════════════════════════════
  848.     Segment Data 'Data'
  849. ;════════════════════════════════════════════════════════════════════════════
  850.  
  851.  
  852.  
  853.     Label Sintable Word
  854.  
  855.     include "sintable.inc"
  856.  
  857.     Label Tex Byte
  858.  
  859.     include "texture.inc"
  860.  
  861.     dw 256 DUP(0)
  862.  
  863.     Label Pal Byte
  864.  
  865.     include "textpal.inc"
  866.  
  867. KXSin   dw 0
  868. KXCos   dw 0
  869. KYSin   dw 0
  870. KYCos   dw 0
  871. KZSin   dw 0
  872. KZCos   dw 0
  873. XRot    dw 0,0,0
  874. ObjDot  dw Point
  875. Point   dw 4,0,1,2,3
  876. XCenter dw 160
  877. YCenter dw 100
  878. KZ      dd 2300
  879. StartOffset dw 0
  880. PageOffset  dw 0
  881. TopP    dw 0
  882. CurTS   dw 0
  883. CurTE   dw 0
  884. CurBS   dw 0
  885. CurBE   dw 0
  886. CurSTS  dw 0
  887. CurSTE  dw 0
  888. CurSBS  dw 0
  889. CurSBE  dw 0
  890.  
  891. SrcTX   dd 0
  892. SrcTY   dd 0
  893. SrcBX   dd 0
  894. SrcBY   dd 0
  895. SrcTXA  dd 0
  896. SrcTYA  dd 0
  897. SrcBXA  dd 0
  898. SrcBYA  dd 0
  899.  
  900. SXA     dd 0
  901. SYA     dd 0
  902.  
  903. DestTX  dw 0
  904. DestTY  dd 0
  905. DestBX  dd 0
  906. DestBY  dd 0
  907. DestTXA dd 0
  908. DestTYA dd 0
  909. DestBXA dd 0
  910. DestBYA dd 0
  911.  
  912. DeltaX  dd 0
  913. DeltaY  dd 0
  914. x1      dw 0
  915. x2      dw 0
  916. y1      dw 0
  917. y2      dw 0
  918. Dest    dw 0
  919. Py      dw 0
  920. Px      dw 0
  921. Sx      dw 0
  922. Top     dw 0
  923. Bot     dw 0
  924. DTop    dw 0
  925. DBot    dw 0
  926. NTop    dw 0
  927. NBot    dw 0
  928. Count   dw 0
  929.  
  930. PolWidht dw 0
  931. Color   db 0
  932. Frames  dw 0
  933. Taulukko dw 1000 DUP(0)
  934.  
  935. Dpist   dw -256*3,320*3,0,256*3,320*3,0,256*3,-320*3,0,-256*3,-320*3,0
  936.  
  937. Rotated dw 500 Dup(0)
  938.  
  939. LABEL   Rows Word
  940.  
  941.     Rept 200
  942.  
  943.     dw Row
  944.  
  945.     Row = Row+80
  946.  
  947.     EndM
  948.  
  949. Poly    dw polygon
  950. polygon dw 0,1,2,3
  951.  
  952. pol     dw 0,1,2,3
  953.  
  954. Polyt   dw pol1
  955.  
  956. pol1    dw 4,0,0,1,2,3
  957.  
  958. Pisteet dw 500 DUP(0)
  959.  
  960. Tpol    dw 0,1,2,3
  961.  
  962. Tpisteet dw 0,0,63,0,63,63,0,63
  963.  
  964.     ENDS
  965.  
  966.     Stack 200h
  967.  
  968.     END start
  969.     END
  970.  
  971.  
  972.